<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>二维数组中的查找</title>
</head>
<body>

</body>
<script>
    function Find(target,matrix){
        debugger
        if(matrix == null || matrix.length === 0 || matrix[0].length === 0){
            return false
        }
        let rows = matrix.length
        let cols = matrix[0].length
        let r = 0
        let c = cols - 1 //[r][c]定位二维数组右上角
        while(r <= rows - 1 && c >= 0){
            if (target === matrix[r][c]){
                return true
            }else if(target > matrix[r][c]){
                r++
            }else{
                c--
            }
        }
        return false
    }

    console.log(Find(5,[
        [1,4,7,11,15],
        [2,5,8,12,19],
        [3,6,9,16,22],
        [10,13,14,17,24],
        [18,21,23,26,30]
    ]))
</script>
</html>
